package com.itheima.stock.mq;

import com.github.benmanes.caffeine.cache.Cache;
import com.itheima.stock.service.StockService;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class StockMqMsgListener {
@Autowired
private Cache<String,Object> cache;
@Autowired
private StockService stockService;


    @RabbitListener(queues = "innerMarketQueue")
    public void refresthInnerMarketInfo(Date startTime){
        //统计发送消息到接受差时
       Long diffTime= DateTime.now().getMillis()- new DateTime(startTime).getMillis();
       if(diffTime>60000L){
           System.out.println(new DateTime().toString("yyy-MM-dd HH:mm:ss"));
           log.error("大盘发送时间:{},延迟秒:{}",new DateTime(startTime).toString("yyy-MM-dd HH:mm:ss"),diffTime);
       }
        //清空缓存并存入新缓存
        cache.invalidate("innerMarketKey");
       stockService.getInnerMarketInfo();

    }



}
